<%@ Page language="vb" CodeFile="addVehicleStep3.aspx.vb" Inherits="addVehicleStep3_aspx_vb" %>

<%
    rowNumber = 0
    partnerID = Request.QueryString("partnerID")
    dealerID = Request.QueryString("dealerID")
    If Len(partnerID) = 0 Or Len(dealerID) = 0 Then 
        Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
    Else
        partnerID = CLng(partnerID)
        dealerID = CLng(dealerID)
    End IF
    If (Request.QueryString("do")) = Nothing Then 
        subDo = Request.QueryString("subDo")
        dbOpen()
        RecSet = Conn.Execute("Select countryID From tblPartner Where partnerID = " & partnerID & "")
        If RecSet.EOF Then 
            Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
        Else
            countryID = RecSet.Fields("countryID").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Over()
        strJS = ""
        strJS = strJS + "[""clientType"", ""<1""],"
        strJS = strJS + "[""client"", ""==''""]"
        checkFields()
        Response.Write("<table cellpadding='0' cellspacing='0' border='0' width='1000'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='3'>CHOOSE A LEASE TAKER - STEP 3 OF 7<font color='#fcbc00'>" & subDo & "</font><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addVehicleStep3.aspx?do=selection&partnerID=" & partnerID & "&dealerID=" & dealerID & "' method='post'>")
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Lease taker:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='clientID' id='clientID'>")
        Response.Write("<option value=''> Select lease taker  ")
        dbOpen()
        RecSet = Conn.Execute("Select clientID, client From tblClient Where countryID = " & countryID & " Order By client")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                intClientID = RecSet.Fields("clientID").Value
                client = RecSet.Fields("client").Value
                Response.Write("<option value='" & intClientID & "'> " & client & " ")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Step 4'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("<form action='addVehicleStep3.aspx?do=save&partnerID=" & partnerID & "&dealerID=" & dealerID & "&countryID=" & countryID & "' method='post' onsubmit=""javascript:return checkFields();"">")
        Response.Write("<tr><td colspan='3'>If you can't find the specific lease taker above, please create a new one in the form below.</td></tr>")
        
        Response.Write("<tr>")
        Response.Write("<td class='formBold'>Customer type:</td>")
        Response.Write("<td align='right'>")
        Response.Write("<select name='clientType' id='clientType'>")
        Response.Write("<option value=''> Select option  ")
        Response.Write("<option value='1'> Private  ")
        Response.Write("<option value='2'> Company  ")
        Response.Write("<option value=''> -------------------------------------- ")
        Response.Write("</select>")
        Response.Write("</td>")
        Response.Write("<td><div id='error_clientType' class='edit_error'>&laquo; OBS!</div></td>")
        Response.Write("</tr>")
        Response.Write("<tr><td class='formBold'></td><td align='right'><font color ='red'>*Fill up only the first text box if a company.</font></td></tr>")
        Response.Write("<tr><td class='formBold'>Name:</td><td align='right'><input type='text' name='client' id='client' size='18' maxlength='50'> <input type='text' name='client_lastName' id='client_lastName' size='18' maxlength='50'></td><td><div id='error_client' class='edit_error'>&laquo; OBS!</div></td></tr>")
        Response.Write("<tr><td class='formBold'>CIN:</td><td align='right'><input type='text' name='cin' id='cin' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Street:</td><td align='right'><input type='text' name='street' id='street' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Zipcode:</td><td align='right'><input type='text' name='zipcode' id='zipcode' size='40' maxlength='50' onkeyup='re=/(\d*)/; re.exec(this.value); this.value=RegExp.$1;'></td></tr>")
        Response.Write("<tr><td class='formBold'>City:</td><td align='right'><input type='text' name='city' id='city' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Areacode:</td><td align='right'><input type='text' name='areacode' id='areacode' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Telephone:</td><td align='right'><input type='text' name='telephone' id='telephone' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td class='formBold'>Email:</td><td align='right'><input type='text' name='email' id='email' size='40' maxlength='50'></td></tr>")
        Response.Write("<tr><td align='right' colspan='2'><input type='submit' value='Save'></td></tr>")
        Response.Write("</form>")
        Response.Write("<tr><td colspan='3'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("<td width='100'></td>")
        Response.Write("<td valign='top'>")
        Response.Write("<table cellpadding='2' cellspacing='2' width='450'>")
        Response.Write("<tr><td class='headline' colspan='2'>SUBSCRIPTION PROCESS<hr class='hrHeadline'></td></tr>")
        dbOpen()
        RecSet = Conn.Execute("Select d.dealer, p.partnerName, c.country From ((tblDealer d INNER JOIN tblPartner p ON p.partnerID = d.partnerID) INNER JOIN tblCountry c ON c.countryID = p.countryID) Where d.dealerID = " & dealerID & "")
        If RecSet.EOF Then 
            Response.Redirect("addVehicleStep1.aspx?subDo=%20-%20CHOOSE%20A%20PARTNER")
        Else
            dealer = RecSet.Fields("dealer").Value
            partnerName = RecSet.Fields("partnerName").Value
            country = RecSet.Fields("country").Value
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Write("<tr bgcolor='#eeeeee'><td>Country:</td><td>" & country & "</td></tr>")
        Response.Write("<tr><td>Partner:</td><td>" & partnerName & "</td></tr>")
        Response.Write("<tr bgcolor='#eeeeee'><td>Car dealer:</td><td>" & dealer & "</td></tr>")
        Response.Write("<tr><td colspan='2'><hr class='hrHeadline'></td></tr>")
        Response.Write("</table>")
        Response.Write("</td>")
        Response.Write("</tr>")
        Response.Write("</table>")
        Under()
    ElseIf Request.QueryString("do") = "save" Then 
        countryID = Request.QueryString("countryID")
        clientType = Request.Form("clientType")
        client = Request.Form("client")
        client_lastName = Request.Form("client_lastName")
        cin = Request.Form("cin")
        street = Request.Form("street")
        zipcode = Request.Form("zipcode")
        city = Request.Form("city")
        areacode = Request.Form("areaCode")
        telephone = Request.Form("telephone")
        email = Request.Form("email")
        userID = fragusLeasingUserID
        clientType = CLng(clientType)
        If Len(client) > 0 Then 
            client = Trim(client)
            client = Replace(CStr(client), "'", "")
            client = Replace(CStr(client), """", "")
            client = Replace(CStr(client), "<", "")
            client = Replace(CStr(client), ">", "")
            client = Replace(CStr(client), "=", "")
        End If
        client_lastName = CleanString(client_lastName )
        If Len(cin) > 0 Then 
            cin = Trim(cin)
            cin = Replace(cin, "'", "")
            cin = Replace(cin, """", "")
            cin = Replace(cin, "<", "")
            cin = Replace(cin, ">", "")
            cin = Replace(cin, "=", "")
        Else
            cin = "N/A"
        End IF
        If Len(street) > 0 Then 
            street = Trim(street)
            street = Replace(street, "'", "")
            street = Replace(street, """", "")
            street = Replace(street, "<", "")
            street = Replace(street, ">", "")
            street = Replace(street, "=", "")
        End IF
        If Len(zipcode) > 0 Then 
            zipcode = Trim(zipcode)
            zipcode = Replace(zipcode, "'", "")
            zipcode = Replace(zipcode, """", "")
            zipcode = Replace(zipcode, "<", "")
            zipcode = Replace(zipcode, ">", "")
            zipcode = Replace(zipcode, "=", "")
        End IF
        If Len(city) > 0 Then 
            city = Trim(city)
            city = Replace(city, "'", "")
            city = Replace(city, """", "")
            city = Replace(city, "<", "")
            city = Replace(city, ">", "")
            city = Replace(city, "=", "")
        End IF
        If Len(areacode) > 0 Then 
            areacode = Trim(areacode)
            areacode = Replace(areacode, "'", "")
            areacode = Replace(areacode, """", "")
            areacode = Replace(areacode, "<", "")
            areacode = Replace(areacode, ">", "")
            areacode = Replace(areacode, "=", "")
        End IF
        If Len(telephone) > 0 Then 
            telephone = Trim(telephone)
            telephone = Replace(telephone, "'", "")
            telephone = Replace(telephone, """", "")
            telephone = Replace(telephone, "<", "")
            telephone = Replace(telephone, ">", "")
            telephone = Replace(telephone, "=", "")
        End IF
        If Len(email) > 0 Then 
            email = Trim(email)
            email = Replace(email, "'", "")
            email = Replace(email, """", "")
            email = Replace(email, "<", "")
            email = Replace(email, ">", "")
            email = Replace(email, "=", "")
        End IF
        dbOpen()
        Conn.Execute("Insert Into tblClient (userID, countryID, clientType, client, client_lastName, cin, street, zipcode, city, areacode, telephone, email) Values(" & userID & "," & countryID & "," & clientType & ",'" & client & "','" & client_lastName & "','" & cin & "','" & street & "','" & zipcode & "','" & city & "','" & areacode & "','" & telephone & "','" & email & "')")
        dbClose()
        dbOpen()
        RecSet = Conn.Execute("SELECT MAX(clientID) AS clientID FROM tblClient")
        intClientID = RecSet.Fields("clientID").Value
        RecSet.Close()
        RecSet = Nothing
        dbClose()
        Response.Redirect("addVehicleStep4.aspx?partnerID=" & partnerID & "&dealerID=" & dealerID & "&clientID=" & intClientID & "")
    ElseIf Request.QueryString("do") = "selection" Then 
        intClientID = Request.Form("clientID")
        If Len(intClientID) > 0 Then
            Response.Redirect("addVehicleStep4.aspx?partnerID=" & partnerID & "&dealerID=" & dealerID & "&clientID=" & intClientID & "")
        Else
            Response.Redirect("addVehicleStep3.aspx?partnerID=" & partnerID & "&dealerID=" & dealerID & "&subDo=%20-%20CHOOSE%20A%20LEASE%20TAKER")
        End If
    End IF
%>
